package com.example.backend.util;

import org.springframework.beans.BeanUtils;

public class ConvertUtil {
    public static <S, T> T convert(S source, Class<T> targetClass) {
        if (source == null) return null;
        try {
            T target = targetClass.getDeclaredConstructor().newInstance();
            BeanUtils.copyProperties(source, target);
            return target;
        } catch (Exception e) {
            throw new RuntimeException("转换失败", e);
        }
    }
} 